package com.example.controller;

import com.example.domain.menu.MenuTree;
import com.example.domain.vo.Result;
import com.example.service.HomeService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@Slf4j
@RequiredArgsConstructor
@RestController
public class HomeController {

    private final HomeService homeService;

    /**
     * 获取菜单树
     */
    @GetMapping("/menus")
    public Result getMenuList(){
         //调用service层
         List<MenuTree> menuList= homeService.getMenuList();
         //返回数据
        if(menuList.isEmpty()) return Result.error("获取失败");
         return Result.ok(menuList);
    }
}
